#include"Transform.h"

Matrix Transform::Translate(const Vec4f& v)
{
	Matrix m;
	m.Identity();
	m.mat[0][3] = v.x;
	m.mat[1][3] = v.y;
	m.mat[2][3] = v.z;
	return m;
}

Matrix Transform::RotateX(float deg)
{
	float rad = deg2rad(deg);
	rotation.x = deg;
	Matrix m;
	m.Identity();
	float cosv = std::cos(rad);
	float sinv = std::sin(rad);
	m.mat[1][1] = cosv;
	m.mat[1][2] = -sinv;
	m.mat[2][1] = sinv;
	m.mat[2][2] = cosv;
	return m;
}

Matrix Transform::RotateY(float deg)
{
	float rad = deg2rad(deg);
	rotation.y = deg;
	Matrix m;
	m.Identity();
	float cosv = std::cos(rad);
	float sinv = std::sin(rad);
	m.mat[0][0] = cosv;
	m.mat[0][2] = sinv;
	m.mat[2][0] = -sinv;
	m.mat[2][2] = cosv;
	return m;
}

Matrix Transform::RotateZ(float deg)
{
	float rad = deg2rad(deg);
	rotation.x = deg;
	Matrix m;
	m.Identity();
	float cosv = std::cos(rad);
	float sinv = std::sin(rad);
	m.mat[0][0] = cosv;
	m.mat[0][1] = -sinv;
	m.mat[1][0] = sinv;
	m.mat[1][1] = cosv;
	return m;
}

Matrix Transform::Rotate(const Vec4f& degv)
{
	rotation = degv;
	Matrix rotx = RotateX(degv.x);
	Matrix roty = RotateY(degv.y);
	Matrix rotz = RotateZ(degv.z);
	return rotx * roty * rotz;
}

Matrix Transform::Scale(const Vec4f& v)
{
	Matrix m;
	m.Identity();
	scale = v;
	m.mat[0][0] = v.x;
	m.mat[1][1] = v.y;
	m.mat[2][2] = v.z;
	return m;
}
